import datetime


class DateUtils:
    """
        日期工具类
    """

    @staticmethod
    def get_current_date(format_str="%Y-%m-%d"):
        """
        获取当前日期
        :return:
        """
        return datetime.datetime.now().strftime(format_str)

    @staticmethod
    def get_current_time(format_str="%H:%M:%S"):
        """
        获取当前时间
        :return:
        """

        return datetime.datetime.now().strftime(format_str)

    @staticmethod
    def parse_date(date_str, format_str="%Y-%m-%d"):
        """
        将日期字符串转换为日期对象
        :param date_str:
        :param format_str:
        :return:
        """
        return datetime.datetime.strptime(date_str, format_str)

    @staticmethod
    def parse_time(time_str, format_str="%H:%M:%S"):
        """
        将时间字符串转换为时间对象
        :param time_str:
        :param format_str:
        :return:
        """
        return datetime.datetime.strptime(time_str, format_str)

    @staticmethod
    def get_current_datetime(format_str="%Y-%m-%d %H:%M:%S"):
        """
        获取当前日期和时间
        :return:
        """
        return datetime.datetime.now().strftime(format_str)

    @staticmethod
    def get_current_timestamp():
        """
        获取当前时间戳
        :return:
        """
        return datetime.datetime.now().timestamp()

    @staticmethod
    def parse_datetime(datetime_str, format_str="%Y-%m-%d %H:%M:%S"):
        return datetime.datetime.strptime(datetime_str, format_str)

    @staticmethod
    def compare_time(first_time, second_time):
        """
        比较两个时间的大小,第一个时间大于第二个时间返回1，第一个时间小于第二个时间返回-1，第一个时间等于第二个时间返回0
        :return:
        """

        if first_time > second_time:
            return 1
        elif first_time < second_time:
            return -1
        else:
            return 0

    @staticmethod
    def compare_date(first_date, second_date):
        """
        比较两个日期的大小,第一个日期大于第二个日期返回1，第一个日期小于第二个日期返回-1，第一个日期等于第二个日期返回0
        :return:
        """

        if first_date > second_date:
            return 1
        elif first_date < second_date:
            return -1
        else:
            return 0

    @staticmethod
    def add_days(date, days):
        """
        向日期对象添加天数
        :param date:
        :param days:
        :return:
        """
        return date + datetime.timedelta(days=days)

    @staticmethod
    def add_months(date, months):
        """
        向日期对象添加月数
        :param date:
        :param months:
        :return:
        """
        return date + datetime.timedelta(months=months)

    @staticmethod
    def add_years(date, years):
        """
        向日期对象添加年数
        :param date:
        :param years:
        :return:
        """
        return date + datetime.timedelta(years=years)

    @staticmethod
    def add_hours(date, hours):
        """
        向日期对象添加小时数
        :param date:
        :param hours:
        :return:
        """
        return date + datetime.timedelta(hours=hours)

    @staticmethod
    def add_minutes(date, minutes):
        """
        向日期对象添加分钟数
        :param date:
        :param minutes:
        :return:
        """
        return date + datetime.timedelta(minutes=minutes)


    @staticmethod
    def subtract_days(date, days):
        """
        从日期对象减去天数
        :param date:
        :param days:
        :return:
        """
        return date - datetime.timedelta(days=days)

    @staticmethod
    def subtract_months(date, months):
        """
        从日期对象减去月数
        :param date:
        :param months:
        :return:
        """
        return date - datetime.timedelta(months=months)

    @staticmethod
    def subtract_years(date, years):
        """
        从日期对象减去年数
        :param date:
        :param years:
        :return:
        """
        return date - datetime.timedelta(years=years)

    @staticmethod
    def subtract_hours(date, hours):
        """
        从日期对象减去小时数
        :param date:
        :param hours:
        :return:
        """
        return date - datetime.timedelta(hours=hours)

    @staticmethod
    def subtract_minutes(date, minutes):
        """
        从日期对象减去分钟数
        :param date:
        :param minutes:
        :return:
        """
        return date - datetime.timedelta(minutes=minutes)

    @staticmethod
    def get_day_of_week(date):
        """
        获取日期对象的星期几
        :param date:
        :return:
        """
        return date.weekday()

    @staticmethod
    def get_day_of_month(date):
        """
        获取日期对象的当月天数
        :param date:
        :return:
        """
        return date.day

    @staticmethod
    def get_day_of_year(date):
        """
        获取日期对象的当年天数
        :param date:
        :return:
        """
        return date.timetuple().tm_yday

    @staticmethod
    def get_week_of_year(date):
        """
        获取日期对象的当年第几周
        :param date:
        :return:
        """
        return date.isocalendar()[1]

    @staticmethod
    def get_month_of_year(date):
        """
        获取日期对象的当年第几月
        :param date:
        :return:
        """
        return date.month

    @staticmethod
    def get_year(date):
        """
        获取日期对象的年份
        :param date:
        :return:
        """
        return date.year

    @staticmethod
    def get_hour(date):
        """
        获取日期对象的小时数
        :param date:
        :return:
        """
        return date.hour

    @staticmethod
    def get_minute(date):
        """
        获取日期对象的分钟数
        :param date:
        :return:
        """
        return date.minute

    @staticmethod
    def get_second(date):
        """
        获取日期对象的秒数
        :param date:
        :return:
        """
        return date.second


